﻿@{
    ViewBag.Title = "数据库备份";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}
<script>
    $(function () {
        InitialPage();
        GetTree();
        GetGrid();
    });
    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 141);
                $("#itemTree").setTreeHeight($(window).height() - 52);
            }, 200);
            e.stopPropagation();
        });
    }
    //加载树
    var _DataBaseLinkId = "";
    function GetTree() {
        var item = {
            height: $(window).height() - 52,
            url: "../../SystemManage/DataBaseLink/GetTreeJson",
            onnodeclick: function (item) {
                if (item.parentnodes) {
                    _DataBaseLinkId = item.id;
                    $("#titleinfo").html("[" + item.text + "]&nbsp;[" + item.parentnodes + "]&nbsp;[" + item.title + "]");
                    $("#txt_Keyword").val("");
                    $('#btn_Search').trigger("click");
                }
            }
        };
        //初始化
        $("#itemTree").treeview(item);
    }
    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var $gridTable = $("#gridTable");
        $gridTable.jqGrid({
            datatype: "json",
            height: $(window).height() - 141,
            autowidth: true,
            colModel: [
                { label: '主键', name: 'F_DatabaseBackupId', hidden: true },
                { label: '计划编号', name: 'F_EnCode', index: 'F_EnCode', width: 100, align: 'left' },
                { label: '计划名称', name: 'F_FullName', index: 'F_FullName', width: 200, align: 'left' },
                {
                    label: '执行方式', name: 'F_ExecuteMode', index: 'F_ExecuteMode', width: 100, align: 'center',
                    formatter: function (cellvalue, options, rowObject) {
                        switch (cellvalue) {
                            case 0:
                                return "每天";
                            case 1:
                                return "每周一";
                            case 2:
                                return "每周二";
                            case 3:
                                return "每周三";
                            case 4:
                                return "每周四";
                            case 5:
                                return "每周五";
                            case 6:
                                return "每周六";
                            case 7:
                                return "每周日";
                            default:
                                return "";
                        }
                    }
                },
                { label: '执行时间', name: 'F_ExecuteTime', index: 'F_ExecuteTime', width: 100, align: 'center' },
                { label: '备份路径', name: 'F_BackupPath', index: 'F_BackupPath', width: 300, align: 'left' },
                {
                    label: "执行状态", name: "F_EnabledMark", index: "F_EnabledMark", width: 80, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue == 1) {
                            return '<span value=' + cellvalue + ' class=\"label label-success\">启用</span>';
                        } else if (cellvalue == 0) {
                            return '<span value=' + cellvalue + ' class=\"label label-danger\">停用</span>';
                        } else {
                            return '未启用';
                        }
                    }
                },
                { label: "描述", name: "F_Description", index: "F_Description", width: 200, align: "left" }
            ],
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            },
            rowNum: "1000",
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            subGrid: true,
            subGridRowExpanded: function (subgrid_id, row_id) {
                var databaseBackupId = $gridTable.jqGrid('getRowData', row_id)['F_DatabaseBackupId'];
                var subgrid_table_id = subgrid_id + "_t";
                $("#" + subgrid_id).html("<table id='" + subgrid_table_id + "'></table>");
                $("#" + subgrid_table_id).jqGrid({
                    url: "../../SystemManage/DataBaseBackup/GetPathListJson",
                    postData: { databaseBackupId: databaseBackupId },
                    datatype: "json",
                    height: 260,
                    colModel: [
                        { label: '主键', name: 'F_DatabaseBackupId', hidden: true },
                        { label: '创建时间', name: 'F_ExecuteTime', index: 'F_ExecuteTime', width: 150, align: 'left' },
                        { label: '文件大小', name: 'F_FullName', index: 'F_FullName', width: 100, align: 'left' },
                        { label: '文件路径', name: 'F_FullName', index: 'F_FullName', width: 500, align: 'left' }
                    ],
                    caption: "备份文件信息列表",
                    rowNum: "1000",
                    rownumbers: true,
                    shrinkToFit: false,
                    gridview: true,
                    hidegrid: false
                });
            }
        });
        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = {
                condition: $("#queryCondition").find('.dropdown-text').attr('data-value'),
                keyword: $("#txt_Keyword").val()
            }
            $gridTable.jqGrid('setGridParam', {
                url: "../../SystemManage/DataBaseBackup/GetListJson",
                postData: { dataBaseLinkId: _DataBaseLinkId, queryJson: JSON.stringify(queryJson) },
                page: 1
            }).trigger('reloadGrid');
        });
        //查询回车
        $('#txt_Keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
        ////查询事件
        //$("#btn_Search").click(function () {
        //    $gridTable.resetSelection();
        //    selectedRowIndex = 0;
        //    $gridTable.jqGrid('setGridParam', {
        //        url: "../../SystemManage/DataBaseBackup/GetListJson",
        //        postData: { dataBaseLinkId: _DataBaseLinkId, keyword: $("#txt_Keyword").val() },
        //    }).trigger('reloadGrid');
        //});
    }
    //新增
    function btn_add() {
        if (_DataBaseLinkId) {
            dialogOpen({
                id: "Form",
                title: '添加计划',
                url: '/SystemManage/DataBaseBackup/Form?dataBaseLinkId=' + _DataBaseLinkId,
                width: "500px",
                height: "450px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });
        } else {
            dialogMsg('请选择左边数据库！', 0);
        }
    };
    //编辑
    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("F_DatabaseBackupId");
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "Form",
                title: '编辑计划',
                url: '/SystemManage/DataBaseBackup/Form?keyValue=' + keyValue,
                width: "500px",
                height: "470px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });
        }
    }
    //删除
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("F_DatabaseBackupId");
        if (keyValue) {
            $.RemoveForm({
                url: "../../SystemManage/DataBaseBackup/RemoveForm",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择需要删除的计划！', 0);
        }
    }
</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel">
            <div class="panel-Title">数据库目录</div>
            <div id="itemTree"></div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="panel-Title">
                数据库备份和还原 - <span id="titleinfo">未选择数据库</span>
            </div>
            <div class="titlePanel">
                <div class="title-search">
                    <table>
                        <tr>
                            <td>
                                <div id="queryCondition" class="btn-group">
                                    <a class="btn btn-default dropdown-text" data-toggle="dropdown">选择条件</a>
                                    <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                                    <ul class="dropdown-menu">
                                        <li><a data-value="EnCode">计划编号</a></li>
                                        <li><a data-value="FullName">计划名称</a></li>
                                    </ul>
                                </div>
                            </td>
                            <td style="padding-left: 2px;">
                                <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
                            </td>
                            <td style="padding-left: 5px;">
                                <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                        <a id="lr-edit" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                        <a id="lr-delete" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                    </div>
                    <div class="btn-group">
                        <a id="lr-disabled" class="btn btn-default" onclick="btn_disabled()"><i class="fa fa-stop"></i>&nbsp;停用</a>
                        <a id="lr-enabled" class="btn btn-default" onclick="btn_enabled()"><i class="fa fa-play"></i>&nbsp;启用</a>
                    </div>
                    <script>$('.toolbar').authorizeButton()</script>
                </div>
            </div>
            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>
</div>

